﻿namespace Fiddler
{
    using System;
    using System.IO;
    using System.Runtime.Serialization;

    [Serializable]
    public class SessionData : ISerializable
    {
        public byte[] oMetadata;
        public byte[] oRequest;
        public byte[] oResponse;

        public SessionData(Session oS)
        {
            MemoryStream oFS = new MemoryStream();
            oS.WriteRequestToStream(false, true, oFS);
            this.oRequest = oFS.GetBuffer();
            oFS = new MemoryStream();
            oS.WriteResponseToStream(oFS, false);
            this.oResponse = oFS.GetBuffer();
            oFS = new MemoryStream();
            oS.WriteMetadataToStream(oFS);
            this.oMetadata = oFS.GetBuffer();
        }

        public SessionData(SerializationInfo info, StreamingContext ctxt)
        {
            this.oRequest = (byte[]) info.GetValue("Request", typeof(byte[]));
            this.oResponse = (byte[]) info.GetValue("Response", typeof(byte[]));
            this.oMetadata = (byte[]) info.GetValue("Metadata", typeof(byte[]));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("Request", this.oRequest);
            info.AddValue("Response", this.oResponse);
            info.AddValue("Metadata", this.oMetadata);
        }
    }
}

